home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / AmazingTour.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-02-04  |  8.3 KB  |  257 lines

  1. import java.awt.Button;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Event;
  6. import java.awt.FileDialog;
  7. import java.awt.Font;
  8. import java.awt.Frame;
  9. import java.awt.Label;
  10. import java.awt.LayoutManager;
  11. import java.awt.Menu;
  12. import java.awt.MenuBar;
  13. import java.awt.MenuItem;
  14. import java.awt.Rectangle;
  15. import java.io.DataInputStream;
  16. import java.io.FileInputStream;
  17. import java.io.FileNotFoundException;
  18. import java.io.FilterInputStream;
  19. import java.io.IOException;
  20. import java.net.MalformedURLException;
  21. import java.net.URL;
  22. import symantec.itools.awt.WrappingLabel;
  23. import symantec.itools.multimedia.ImageViewer;
  24. import symantec.itools.multimedia.SlideShow;
  25. import symantec.itools.net.RelativeURL;
  26.  
  27. public class AmazingTour extends Frame {
  28.    int dayCount;
  29.    String fileName;
  30.    Rectangle slideShowBounds;
  31.    FileDialog openFileDialog1;
  32.    WrappingLabel wrappingLabelStart;
  33.    Label labelDay;
  34.    WrappingLabel wrappingLabelPeople;
  35.    SlideShow slideShowItinerary;
  36.    WrappingLabel wrappingLabelDesc;
  37.    ImageViewer imageViewerLogo;
  38.    Button buttonPrevious;
  39.    Button buttonNext;
  40.    WrappingLabel wrappingLabelTop;
  41.    MenuBar mainMenuBar;
  42.    Menu menu1;
  43.    Menu menu3;
  44.  
  45.    void slideShowItinerary_SlideChanged(Event event) {
  46.       this.buttonNext.enable(!this.slideShowItinerary.isAtLastImage());
  47.       this.buttonPrevious.enable(!this.slideShowItinerary.isAtFirstImage());
  48.       this.wrappingLabelDesc.setText(this.slideShowItinerary.getDescription(this.slideShowItinerary.getCurrentImageIndex()));
  49.    }
  50.  
  51.    void buttonNext_Clicked(Event event) {
  52.       this.slideShowItinerary.nextImage();
  53.       this.labelDay.setText("Day " + ++this.dayCount);
  54.    }
  55.  
  56.    void buttonPrevious_Clicked(Event event) {
  57.       this.slideShowItinerary.previousImage();
  58.       this.labelDay.setText("Day " + --this.dayCount);
  59.    }
  60.  
  61.    void Open_Action(Event event) {
  62.       this.openFileDialog1.show();
  63.       String tempFileName = this.openFileDialog1.getDirectory() + this.openFileDialog1.getFile();
  64.       if ((this.fileName != null || tempFileName.endsWith(".dat")) && tempFileName.endsWith(".dat")) {
  65.          if (this.fileName == null) {
  66.             this.wrappingLabelStart.hide();
  67.          }
  68.  
  69.          this.fileName = tempFileName;
  70.          if (this.slideShowItinerary != null) {
  71.             ((Container)this).remove(this.slideShowItinerary);
  72.          }
  73.  
  74.          this.dayCount = 1;
  75.          this.slideShowItinerary = new SlideShow();
  76.          this.slideShowItinerary.reshape(((Container)this).insets().left + this.slideShowBounds.x, ((Container)this).insets().top + this.slideShowBounds.y, this.slideShowBounds.width, this.slideShowBounds.height);
  77.          ((Container)this).add(this.slideShowItinerary);
  78.          this.getEntries(this.openFileDialog1.getDirectory(), this.fileName);
  79.          this.buttonNext.show();
  80.          this.buttonPrevious.show();
  81.          this.wrappingLabelTop.setText("Custom Itinerary for");
  82.          this.labelDay.setText("Day " + this.dayCount);
  83.          this.wrappingLabelDesc.setText(this.slideShowItinerary.getDescription(this.slideShowItinerary.getCurrentImageIndex()));
  84.          this.buttonPrevious.disable();
  85.          if (this.slideShowItinerary.isAtLastImage()) {
  86.             this.buttonNext.disable();
  87.          } else {
  88.             this.buttonNext.enable();
  89.          }
  90.       }
  91.    }
  92.  
  93.    void About_Action(Event event) {
  94.       (new AboutDialog(this, true)).show();
  95.    }
  96.  
  97.    void Exit_Action(Event event) {
  98.       (new QuitDialog(this, true)).show();
  99.    }
  100.  
  101.    public AmazingTour() {
  102.       this.dayCount = 1;
  103.       new AboutDialog(this, true);
  104.       new QuitDialog(this, true);
  105.       ((Container)this).setLayout((LayoutManager)null);
  106.       ((Frame)this).addNotify();
  107.       ((Component)this).resize(((Container)this).insets().left + ((Container)this).insets().right + 595, ((Container)this).insets().top + ((Container)this).insets().bottom + 550);
  108.       ((Component)this).setFont(new Font("Dialog", 1, 12));
  109.       ((Component)this).setForeground(new Color(0));
  110.       ((Component)this).setBackground(new Color(16777215));
  111.       this.openFileDialog1 = new FileDialog(this, "Open", 0);
  112.       this.wrappingLabelStart = new WrappingLabel();
  113.       this.wrappingLabelStart.reshape(((Container)this).insets().left + 8, ((Container)this).insets().top + 24, 225, 132);
  114.       this.wrappingLabelStart.setFont(new Font("Dialog", 1, 16));
  115.       ((Container)this).add(this.wrappingLabelStart);
  116.       this.wrappingLabelStart.setAlignStyle(0);
  117.       this.wrappingLabelStart.setText("To start, choose Open from the File menu and open your data file. Your .dat file and the graphics files must be in the same directory.");
  118.       this.labelDay = new Label("", 1);
  119.       this.labelDay.reshape(((Container)this).insets().left + 72, ((Container)this).insets().top + 208, 86, 26);
  120.       this.labelDay.setFont(new Font("Dialog", 2, 16));
  121.       ((Container)this).add(this.labelDay);
  122.       this.wrappingLabelPeople = new WrappingLabel();
  123.       this.wrappingLabelPeople.reshape(((Container)this).insets().left + 8, ((Container)this).insets().top + 88, 232, 88);
  124.       this.wrappingLabelPeople.setFont(new Font("Dialog", 1, 24));
  125.       ((Container)this).add(this.wrappingLabelPeople);
  126.       this.wrappingLabelPeople.setAlignStyle(1);
  127.       this.wrappingLabelPeople.setText("");
  128.       this.slideShowItinerary = new SlideShow();
  129.       this.slideShowItinerary.reshape(((Container)this).insets().left + 251, ((Container)this).insets().top + 219, 340, 235);
  130.       ((Container)this).add(this.slideShowItinerary);
  131.       this.wrappingLabelDesc = new WrappingLabel();
  132.       this.wrappingLabelDesc.reshape(((Container)this).insets().left + 16, ((Container)this).insets().top + 248, 224, 272);
  133.       this.wrappingLabelDesc.setFont(new Font("Dialog", 0, 14));
  134.       ((Container)this).add(this.wrappingLabelDesc);
  135.       this.wrappingLabelDesc.setAlignStyle(0);
  136.       this.wrappingLabelDesc.setText("");
  137.       this.imageViewerLogo = new ImageViewer();
  138.       this.imageViewerLogo.reshape(((Container)this).insets().left + 256, ((Container)this).insets().top + 16, 320, 217);
  139.       ((Container)this).add(this.imageViewerLogo);
  140.  
  141.       try {
  142.          this.imageViewerLogo.setURL(RelativeURL.getURL("Images/Logo.gif"));
  143.       } catch (MalformedURLException var1) {
  144.       }
  145.  
  146.       this.buttonPrevious = new Button("Previous");
  147.       this.buttonPrevious.hide();
  148.       this.buttonPrevious.reshape(((Container)this).insets().left + 336, ((Container)this).insets().top + 496, 82, 25);
  149.       ((Container)this).add(this.buttonPrevious);
  150.       this.buttonNext = new Button("Next");
  151.       this.buttonNext.hide();
  152.       this.buttonNext.reshape(((Container)this).insets().left + 424, ((Container)this).insets().top + 496, 82, 25);
  153.       ((Container)this).add(this.buttonNext);
  154.       this.wrappingLabelTop = new WrappingLabel();
  155.       this.wrappingLabelTop.reshape(((Container)this).insets().left + 8, ((Container)this).insets().top + 40, 232, 38);
  156.       this.wrappingLabelTop.setFont(new Font("Dialog", 1, 16));
  157.       ((Container)this).add(this.wrappingLabelTop);
  158.       this.wrappingLabelTop.setAlignStyle(1);
  159.       this.wrappingLabelTop.setText("");
  160.       ((Frame)this).setTitle("Amazing Adventures Travel - Custom Itinerary Application");
  161.       this.slideShowBounds = this.slideShowItinerary.bounds();
  162.       this.mainMenuBar = new MenuBar();
  163.       this.menu1 = new Menu("File");
  164.       this.menu1.add("Open...");
  165.       this.menu1.addSeparator();
  166.       this.menu1.add("Exit");
  167.       this.mainMenuBar.add(this.menu1);
  168.       this.menu3 = new Menu("Help");
  169.       this.mainMenuBar.setHelpMenu(this.menu3);
  170.       this.menu3.add("About");
  171.       this.mainMenuBar.add(this.menu3);
  172.       ((Frame)this).setMenuBar(this.mainMenuBar);
  173.    }
  174.  
  175.    public AmazingTour(String title) {
  176.       this();
  177.       ((Frame)this).setTitle(title);
  178.    }
  179.  
  180.    public synchronized void show() {
  181.       ((Component)this).move(50, 50);
  182.       super.show();
  183.    }
  184.  
  185.    public boolean handleEvent(Event event) {
  186.       if (event.target == this.buttonPrevious && event.id == 1001) {
  187.          this.buttonPrevious_Clicked(event);
  188.       }
  189.  
  190.       if (event.target == this.buttonNext && event.id == 1001) {
  191.          this.buttonNext_Clicked(event);
  192.       }
  193.  
  194.       if (event.target == this.slideShowItinerary && event.id == 1001) {
  195.          this.slideShowItinerary_SlideChanged(event);
  196.       }
  197.  
  198.       if (event.id == 201) {
  199.          ((Component)this).hide();
  200.          ((Frame)this).dispose();
  201.          System.exit(0);
  202.          return true;
  203.       } else {
  204.          return super.handleEvent(event);
  205.       }
  206.    }
  207.  
  208.    public boolean action(Event event, Object arg) {
  209.       if (event.target instanceof MenuItem) {
  210.          String label = (String)arg;
  211.          if (label.equalsIgnoreCase("Open...")) {
  212.             this.Open_Action(event);
  213.             return true;
  214.          }
  215.  
  216.          if (label.equalsIgnoreCase("About")) {
  217.             this.About_Action(event);
  218.             return true;
  219.          }
  220.  
  221.          if (label.equalsIgnoreCase("Exit")) {
  222.             this.Exit_Action(event);
  223.             return true;
  224.          }
  225.       }
  226.  
  227.       return super.action(event, arg);
  228.    }
  229.  
  230.    public static void main(String[] args) {
  231.       (new AmazingTour()).show();
  232.    }
  233.  
  234.    private void getEntries(String dir, String filename) {
  235.       try {
  236.          DataInputStream in = new DataInputStream(new FileInputStream(filename));
  237.          this.wrappingLabelPeople.setText(in.readLine());
  238.          int numEntries = Integer.parseInt(in.readLine());
  239.          dir = "file:/" + dir.substring(0, dir.lastIndexOf(92));
  240.  
  241.          for(int i = 0; i < numEntries; ++i) {
  242.             String s1 = dir + "/" + in.readLine();
  243.             String s2 = in.readLine();
  244.             this.slideShowItinerary.addImageAndDescription(new URL(s1), s2);
  245.          }
  246.  
  247.          ((FilterInputStream)in).close();
  248.          ((Component)this).invalidate();
  249.          ((Container)this).validate();
  250.       } catch (FileNotFoundException var8) {
  251.          System.err.println("Can't open " + filename);
  252.       } catch (IOException var9) {
  253.          System.err.println("Error reading " + filename);
  254.       }
  255.    }
  256. }
  257.